package com.etone.smartAudit.controller;

import com.etone.smartAudit.dto.dataModelType.DataModelTypeDTO;
import com.etone.smartAudit.service.DataModelTypeService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.dataModelType.DataModelTypeTreeVO;
import com.etone.smartAudit.vo.dataModelType.DataModelTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: sovy
 * @date: 2020/11/5
 * @description:
 */
@AllArgsConstructor
@RestController
@Api(tags = "数据模型分类类型", value = "DataModelTypeController")
public class DataModelTypeController {

    private DataModelTypeService dataModelTypeService;

    @ApiOperation(value = "数据模型分类列表《完》")
    @GetMapping("/dataModelTypes")
    private PagerVO<DataModelTypeVO> list(
            @ApiParam(value = "父级id，顶级为0") @RequestParam(required = false) Integer pid,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        return dataModelTypeService.list(pid, page, pageSize);
    }

    @ApiOperation(value = "数据模型分类详情《完》")
    @GetMapping("/dataModelTypes/{id}")
    public DataModelTypeVO detail(
            @ApiParam(value = "id", required = true) @PathVariable Integer id
    ) {
        return dataModelTypeService.detail(id);
    }

    @ApiOperation(value = "数据模型分类树形结构《完》")
    @GetMapping("/dataModelTypes/tree")
    public List<DataModelTypeTreeVO> listTree() {
        return dataModelTypeService.listTree();
    }

    @ApiOperation(value = "增加数据模型分类《完》")
    @PostMapping("/dataModelTypes")
    public void add(
            @ApiParam(value = "数据模型分类表单") @RequestBody @Validated DataModelTypeDTO dataModelTypeDTO
    ) {
        dataModelTypeService.save(null, dataModelTypeDTO);
    }

    @ApiOperation(value = "编辑数据模型分类《完》")
    @PutMapping("/dataModelTypes/{id}")
    public void edit(
            @ApiParam(value = "id", required = true) @PathVariable Integer id,
            @ApiParam(value = "数据模型分类表单") @RequestBody @Validated DataModelTypeDTO dataModelTypeDTO
    ) {
        dataModelTypeService.save(id, dataModelTypeDTO);
    }

    @ApiOperation(value = "删除数据模型分类《完》")
    @DeleteMapping("/dataModelTypes/{id}")
    public void delete(@ApiParam(value = "id", required = true) @PathVariable Integer id) {
        dataModelTypeService.removeById(id);
    }

    @ApiOperation(value = "批量删除数据模型分类《完》")
    @DeleteMapping("/dataModelTypes/batch/{ids}")
    public void batchDelete(@ApiParam(value = "ids", required = true) @PathVariable List<Integer> ids) {
        dataModelTypeService.removeByIds(ids);
    }


}
